/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.minierp.bean.FeeBillBean;
import com.minierp.bean.QueryParameterBean;
import com.minierp.bean.QueryResult;
import com.minierp.bean.UserBean;
import com.minierp.bean.UserStatus;
import com.minierp.dao.BankAccountBalanceDao;
import com.minierp.dao.BankAccountDao;
import com.minierp.dao.BankAccountDetailDao;
import com.minierp.dao.BusinessBillDao;
import com.minierp.dao.CodeRuleDao;
import com.minierp.dao.DepartmentDao;
import com.minierp.dao.FeeBillDao;
import com.minierp.dao.FeeBillItemDao;
import com.minierp.dao.FeeTypeDao;
import com.minierp.dao.IdGenerator;
import com.minierp.dao.PayModeDao;
import com.minierp.dao.QueryDao;
import com.minierp.dao.TallySetDao;
import com.minierp.err.NotAllowException;
import com.minierp.err.PermissionDennyException;
import com.minierp.helper.EncCommonHelper;
import com.minierp.helper.EncFeeBillMACtrHelper;
import com.minierp.helper.EncInterceptorHelper;
import com.minierp.helper.PageHelper;
import com.minierp.model.BankAccount;
import com.minierp.model.Department;
import com.minierp.model.EnterpriseInfo;
import com.minierp.model.FeeBill;
import com.minierp.model.FeeBillItem;
import com.minierp.model.TallySet;
import com.minierp.service.FeeBillService;
import com.minierp.view.FeeBillItemListExcelView;
import com.minierp.view.FeeBillListExcelView;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import org.springframework.dao.CannotAcquireLockException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class FeeBillMACtr extends MultiActionController {
	private String dialogSuccessView;
	private String listForExamineView;
	private String infoForExamineView;
	private String listForUnExamineView;
	private String infoForUnExamineView;
	private String searchResultView;
	private String itemSearchResultView;
	private String downloadView;
	private String listForCancelView;
	private String infoForCancelView;
	private String listForBusinessBillView;
	private String printView;
	private FeeBillDao feeBillDao;
	private FeeBillItemDao feeBillItemDao;
	private DepartmentDao departmentDao;
	private BankAccountDao bankAccountDao;
	private BankAccountBalanceDao bankAccountBalanceDao;
	private BankAccountDetailDao bankAccountDetailDao;
	private PayModeDao payModeDao;
	private FeeTypeDao feeTypeDao;
	private TallySetDao tallySetDao;
	private QueryDao queryDao;
	private BusinessBillDao businessBillDao;
	private CodeRuleDao codeRuleDao;
	private IdGenerator idGenerator;
	private FeeBillService feeBillService;
	private DataSource dataSource;

	public String getItemSearchResultView() {
		return this.itemSearchResultView;
	}

	public void setItemSearchResultView(String itemSearchResultView) {
		this.itemSearchResultView = itemSearchResultView;
	}

	public FeeBillItemDao getFeeBillItemDao() {
		return this.feeBillItemDao;
	}

	public void setFeeBillItemDao(FeeBillItemDao feeBillItemDao) {
		this.feeBillItemDao = feeBillItemDao;
	}

	public ModelAndView handleExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.dialogSuccessView);
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		String idStr = request.getParameter("id_str");
		String flag = request.getParameter("flag");
		boolean examined = false;
		if (flag != null && flag.equals("1")) {
			examined = true;
		}

		String[] arr = idStr.split(";");
		boolean num = false;
		String msg;
		int w;
		byte arg13;
		if (!examined) {
			if (!EncCommonHelper.checkPrivilege(request, "FEE_UN_EXAM")) {
				throw new Exception("Permission deny!");
			}

			try {
				for (w = 0; w < arr.length; ++w) {
					this.feeBillService.txUnExamine(Long.parseLong(arr[w]), ub,
							this.feeBillDao, this.feeBillItemDao,
							this.bankAccountBalanceDao,
							this.bankAccountDetailDao, this.businessBillDao,
							this.idGenerator);
				}

				msg = "反审核成功";
			} catch (CannotAcquireLockException arg12) {
				msg = "事务冲突故障，请重新操作！";
			}

			arg13 = 1;
		} else {
			if (!EncCommonHelper.checkPrivilege(request, "FEE_EXAM")) {
				throw new Exception("Permission deny!");
			}

			try {
				for (w = 0; w < arr.length; ++w) {
					this.feeBillService.txExamine(Long.parseLong(arr[w]), ub,
							this.feeBillDao, this.feeBillItemDao,
							this.bankAccountBalanceDao, this.businessBillDao,
							this.idGenerator);
				}

				msg = "审核成功";
			} catch (CannotAcquireLockException arg11) {
				msg = "事务冲突故障，请重新操作！";
			}

			arg13 = 1;
		}

		mv.addObject("returnValue", String.valueOf(arg13));
		EncCommonHelper.setAlertMessage(request, msg);
		return mv;
	}

	public ModelAndView handleListForExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "FEE_EXAM")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.listForExamineView);
			String searchKey = request.getParameter("search_key");
			String tsId = request.getParameter("ts_id");
			UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
			if (tsId == null || tsId.equals("")) {
				tsId = String.valueOf(ub.getUser().getDfTsId());
			}

			Date allowStart = null;
			if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
				allowStart = EncCommonHelper.getEarlDataDate(request);
			}

			List tsList = PageHelper.getTallySetList(this.tallySetDao, ub);
			int perPageNum = EncCommonHelper.getPageSize(request);
			int total = this.feeBillDao.getListCount(searchKey, false,
					Long.parseLong(tsId), ub, allowStart);
			int pageno = EncCommonHelper.getCurrentPageIndex(request, total,
					perPageNum);
			int startIndex = (pageno - 1) * perPageNum;
			List list = this.feeBillDao.getList(searchKey, false,
					Long.parseLong(tsId), ub, allowStart, startIndex,
					perPageNum);
			mv.addObject("qr", EncCommonHelper.parseQueryResult(list, total,
					perPageNum, pageno));
			mv.addObject("searchKey", searchKey);
			mv.addObject("tsId", tsId);
			mv.addObject("tsList", tsList);
			return mv;
		}
	}

	public ModelAndView handleInfoForExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.infoForExamineView);
		String id = request.getParameter("id");
		this.getFeeBill(mv, Long.parseLong(id));
		return mv;
	}

	public ModelAndView handleListForUnExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "FEE_UN_EXAM")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.listForUnExamineView);
			String searchKey = request.getParameter("search_key");
			String tsId = request.getParameter("ts_id");
			UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
			if (tsId == null || tsId.equals("")) {
				tsId = String.valueOf(ub.getUser().getDfTsId());
			}

			Date allowStart = null;
			if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
				allowStart = EncCommonHelper.getEarlDataDate(request);
			}

			List tsList = PageHelper.getTallySetList(this.tallySetDao, ub);
			int perPageNum = EncCommonHelper.getPageSize(request);
			int total = this.feeBillDao.getListCount(searchKey, true,
					Long.parseLong(tsId), ub, allowStart);
			int pageno = EncCommonHelper.getCurrentPageIndex(request, total,
					perPageNum);
			int startIndex = (pageno - 1) * perPageNum;
			List list = this.feeBillDao.getList(searchKey, true,
					Long.parseLong(tsId), ub, allowStart, startIndex,
					perPageNum);
			mv.addObject("qr", EncCommonHelper.parseQueryResult(list, total,
					perPageNum, pageno));
			mv.addObject("searchKey", searchKey);
			mv.addObject("tsId", tsId);
			mv.addObject("tsList", tsList);
			return mv;
		}
	}

	public ModelAndView handleInfoForUnExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.infoForUnExamineView);
		String id = request.getParameter("id");
		this.getFeeBill(mv, Long.parseLong(id));
		return mv;
	}

	public ModelAndView handleListForCancel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "FEE_CANC")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.listForCancelView);
			String searchKey = request.getParameter("search_key");
			String tsId = request.getParameter("ts_id");
			UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
			if (tsId == null || tsId.equals("")) {
				tsId = String.valueOf(ub.getUser().getDfTsId());
			}

			Date allowStart = null;
			if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
				allowStart = EncCommonHelper.getEarlDataDate(request);
			}

			List tsList = PageHelper.getTallySetList(this.tallySetDao, ub);
			int perPageNum = EncCommonHelper.getPageSize(request);
			int total = this.feeBillDao.getListCount(searchKey,
					Long.parseLong(tsId), ub, allowStart);
			int pageno = EncCommonHelper.getCurrentPageIndex(request, total,
					perPageNum);
			int startIndex = (pageno - 1) * perPageNum;
			List list = this.feeBillDao.getList(searchKey,
					Long.parseLong(tsId), ub, allowStart, "", startIndex,
					perPageNum);
			mv.addObject("qr", EncCommonHelper.parseQueryResult(list, total,
					perPageNum, pageno));
			mv.addObject("searchKey", searchKey);
			mv.addObject("tsId", tsId);
			mv.addObject("tsList", tsList);
			return mv;
		}
	}

	public ModelAndView handleInfoForCancel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.infoForCancelView);
		String id = request.getParameter("id");
		this.getFeeBill(mv, Long.parseLong(id));
		return mv;
	}

	public ModelAndView handleCancel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.dialogSuccessView);
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		if (!EncCommonHelper.checkPrivilege(request, "FEE_CANC")) {
			throw new Exception("Permission deny!");
		} else {
			String id = request.getParameter("id");
			String reason = request.getParameter("reason");

			String msg;
			try {
				this.feeBillService.txCancel(Long.parseLong(id), reason, ub,
						this.feeBillDao, this.feeBillItemDao,
						this.bankAccountBalanceDao, this.bankAccountDetailDao,
						this.businessBillDao, this.idGenerator);
				msg = "作废成功！";
			} catch (CannotAcquireLockException arg8) {
				msg = "事务冲突故障，请重新操作！";
			}

			mv.addObject("returnValue", id);
			EncCommonHelper.setAlertMessage(request, msg);
			return mv;
		}
	}

	private void getFeeBill(ModelAndView mv, long id) {
		FeeBill feeBill = (FeeBill) this.feeBillDao.get(FeeBill.class, id);
		if (feeBill != null && feeBill.getTallySetId() != 0L) {
			mv.addObject("tallySet", this.feeBillDao.get(TallySet.class,
					feeBill.getTallySetId()));
		}

		mv.addObject("record", feeBill);
		mv.addObject("itemList", this.feeBillItemDao.getList(feeBill.getId()));
		mv.addObject("bankAccountList", this.bankAccountDao.getList("", ""));
		mv.addObject("departmentList", this.departmentDao.getList(true));
		mv.addObject("feeTypeList", this.feeTypeDao.getList(false));
		if (feeBill.getAttachFile() != null
				&& !feeBill.getAttachFile().equals("")) {
			int beginIndex = feeBill.getAttachFile().lastIndexOf("/");
			mv.addObject("attFile",
					feeBill.getAttachFile().substring(beginIndex + 1));
		}

	}

	public ModelAndView handleSearchResult(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "FEE_BILL_SEAR")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.searchResultView);
			String contentType = request.getParameter("content_type");
			List bankAccountList = this.bankAccountDao.getList("", "");
			List depList = this.departmentDao.getList(true);
			QueryParameterBean b = EncFeeBillMACtrHelper.handleSearchResult(
					request, this.dataSource);
			String[] countObjs = new String[]{"sum(b.cost)"};
			QueryResult qr;
			if (contentType != null && contentType.equals("EXCEL")) {
				qr = this.queryDao.doQuery(b.getQParas(), b.getOParas(),
						(String[]) null, b.getShortNameMap(), b.getRetObjs(),
						countObjs);
				FeeBillListExcelView arg16 = new FeeBillListExcelView();
				HashMap arg18 = new HashMap();
				arg18.put("list", qr.getList());
				arg18.put("baList", bankAccountList);
				arg18.put("depList", depList);
				arg18.put("feeTotal", qr.getExtCount()[0]);
				return new ModelAndView(arg16, arg18);
			} else {
				qr = this.queryDao.doQuery(b.getCurrentPage(), b.getPageSize(),
						b.getQParas(), b.getOParas(), (String[]) null,
						b.getShortNameMap(), b.getRetObjs(), countObjs);
				ArrayList arr = new ArrayList();

				for (int ent = 0; ent < qr.getList().size(); ++ent) {
					FeeBillBean ub = new FeeBillBean();
					FeeBill bill = (FeeBill) qr.getList().get(ent);
					ub.setFeeBill(bill);
					String baName = "";
					if (bill.getBankAccountId() != 0L) {
						for (int j = 0; j < bankAccountList.size(); ++j) {
							BankAccount ba = (BankAccount) bankAccountList
									.get(j);
							if (ba.getId() == bill.getBankAccountId()) {
								baName = ba.getBankName();
								if (ba.getAccountName() != null
										&& !ba.getAccountName().equals("")) {
									baName = baName + "(" + ba.getAccountName()
											+ ")";
								}
							}
						}
					}

					ub.setBankAccountName(baName);
					arr.add(ub);
				}

				qr.setList(arr);
				mv.addAllObjects(b.getParameters());
				mv.addObject("qr", qr);
				mv.addObject("feeTotal", qr.getExtCount()[0]);
				mv.addObject("depList", depList);
				EnterpriseInfo arg17 = EncCommonHelper
						.getEnterpriseInfo(request);
				UserBean arg19 = EncCommonHelper.getCurrentUserAccount(request);
				mv.addObject("myBaList", PageHelper.parseBaList(
						bankAccountList, arg17, arg19, 0L, 0L));
				mv.addObject("tsList",
						PageHelper.getTallySetList(this.tallySetDao, arg19));
				return mv;
			}
		}
	}

	public ModelAndView handleItemSearchResult(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "FEE_ITEM_SEAR")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.itemSearchResultView);
			String contentType = request.getParameter("content_type");
			List bankAccountList = this.bankAccountDao.getList("", "");
			List depList = this.departmentDao.getList(true);
			QueryParameterBean b = EncFeeBillMACtrHelper
					.handleItemSearchResult(request, this.dataSource);
			String[] countObjs = new String[]{"sum(i.cost)"};
			QueryResult qr;
			if (contentType != null && contentType.equals("EXCEL")) {
				qr = this.queryDao.doQuery(b.getQParas(), b.getOParas(),
						(String[]) null, b.getShortNameMap(), b.getRetObjs(),
						countObjs);
				FeeBillItemListExcelView arg17 = new FeeBillItemListExcelView();
				HashMap arg19 = new HashMap();
				arg19.put("list", qr.getList());
				arg19.put("baList", bankAccountList);
				arg19.put("depList", depList);
				arg19.put("ftList", this.feeTypeDao.getList(true));
				arg19.put("feeTotal", qr.getExtCount()[0]);
				return new ModelAndView(arg17, arg19);
			} else {
				qr = this.queryDao.doQuery(b.getCurrentPage(), b.getPageSize(),
						b.getQParas(), b.getOParas(), (String[]) null,
						b.getShortNameMap(), b.getRetObjs(), countObjs);

				for (int ent = 0; ent < qr.getList().size(); ++ent) {
					Object[] ub = (Object[]) qr.getList().get(ent);
					FeeBillBean bean = new FeeBillBean();
					FeeBill bill = (FeeBill) ub[0];
					bean.setFeeBill(bill);
					String baName = "";
					if (bill.getBankAccountId() != 0L) {
						for (int j = 0; j < bankAccountList.size(); ++j) {
							BankAccount ba = (BankAccount) bankAccountList
									.get(j);
							if (ba.getId() == bill.getBankAccountId()) {
								baName = ba.getBankName();
								if (ba.getAccountName() != null
										&& !ba.getAccountName().equals("")) {
									baName = baName + "(" + ba.getAccountName()
											+ ")";
								}
							}
						}
					}

					bean.setBankAccountName(baName);
					ub[0] = bean;
				}

				mv.addAllObjects(b.getParameters());
				mv.addObject("qr", qr);
				mv.addObject("feeTotal", qr.getExtCount()[0]);
				mv.addObject("depList", depList);
				mv.addObject("ftList", this.feeTypeDao.getList(true));
				EnterpriseInfo arg16 = EncCommonHelper
						.getEnterpriseInfo(request);
				UserBean arg18 = EncCommonHelper.getCurrentUserAccount(request);
				mv.addObject("myBaList", PageHelper.parseBaList(
						bankAccountList, arg16, arg18, 0L, 0L));
				mv.addObject("tsList",
						PageHelper.getTallySetList(this.tallySetDao, arg18));
				return mv;
			}
		}
	}

	public ModelAndView handleListForBusinessBill(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.listForBusinessBillView);
		long bbId = Long.parseLong(request.getParameter("bb_id"));
		mv.addObject("items",
				this.feeBillDao.getListForBusinessBill(bbId, true));
		mv.addObject("departmentList", this.departmentDao.getList(true));
		mv.addObject("ftList", this.feeTypeDao.getList(false));
		return mv;
	}

	public ModelAndView handlePrint(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.printView);
		String id = request.getParameter("id");
		this.getFeeBill(mv, Long.parseLong(id));
		mv.addObject("codeRule", this.codeRuleDao.get("FEE_BILL"));
		mv.addObject("retVal", request.getParameter("ret_val"));
		return mv;
	}

	public ModelAndView handleAppList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String json;
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else if (!EncCommonHelper.checkPrivilege(request, "FEE_BILL_SEAR")) {
			map.put("status", "ERROR");
			map.put("errMsg", "您还没有此功能的使用权限，请确认返回！");
		} else {
			try {
				String mapper = request.getParameter("rece_name");
				json = request.getParameter("start_date");
				String out = request.getParameter("end_date");
				String baIdStr = request.getParameter("ba_id");
				String tsIdStr = request.getParameter("ts_id");
				String orde = request.getParameter("orde");
				String showPrev = request.getParameter("show_prev");
				String initQuer = request.getParameter("init_quer");
				long baId = 0L;
				long tsId = 0L;
				if (baIdStr != null && !baIdStr.equals("")) {
					baId = Long.parseLong(baIdStr);
				}

				if (tsIdStr != null && !tsIdStr.equals("")) {
					tsId = Long.parseLong(tsIdStr);
				}

				Date allowStart = null;
				Date startDate = null;
				Date endDate = null;
				if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
					allowStart = EncCommonHelper.getEarlDataDate(request);
				}

				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat sfl = new SimpleDateFormat("yyyy-MM-dd HH:mm");
				if (json != null && !json.equals("")) {
					startDate = sf.parse(json);
				}

				if (out != null && !out.equals("")) {
					endDate = sf.parse(EncCommonHelper.getNextDateStr(out,
							"yyyy-MM-dd"));
				}

				if (startDate == null) {
					startDate = allowStart;
				} else if (allowStart != null && allowStart.after(startDate)) {
					startDate = allowStart;
				}

				if (orde == null || orde.equals("")) {
					orde = "FEE_DATE";
				}

				int total = 0;
				BigDecimal cost = new BigDecimal(0);
				List list = this.feeBillDao.getAppListCount(startDate, endDate,
						mapper, baId, tsId, ub);
				if (list != null && !list.isEmpty() && list.get(0) != null) {
					Object[] perPageNum = (Object[]) list.get(0);
					if (perPageNum[1] != null) {
						total = Integer.parseInt(perPageNum[0].toString());
						cost = (BigDecimal) perPageNum[1];
					}
				}

				map.put("cost", cost);
				map.put("total", Integer.valueOf(total));
				int arg39 = EncCommonHelper.getPageSize(request);
				int pageno = EncCommonHelper.getCurrentPageIndex(request,
						total, arg39);
				if (total > pageno * arg39) {
					map.put("more", "Y");
				} else {
					map.put("more", "N");
				}

				if (showPrev != null && showPrev.equals("Y")) {
					list = this.feeBillDao.getAppList(startDate, endDate,
							mapper, baId, tsId, ub, orde, 0, pageno * arg39);
				} else {
					list = this.feeBillDao.getAppList(startDate, endDate,
							mapper, baId, tsId, ub, orde, (pageno - 1) * arg39,
							arg39);
				}

				List baList = this.bankAccountDao.getList("", "");
				ArrayList items = new ArrayList();

				for (int ent = 0; ent < list.size(); ++ent) {
					HashMap tmpList = new HashMap();
					FeeBill baItems = (FeeBill) list.get(ent);
					String tsItems = "";
					String i = "";
					if (baItems.getCreateTime() != null) {
						tsItems = sfl.format(baItems.getCreateTime());
					}

					if (baItems.getBankAccountId() != 0L) {
						for (int item = 0; item < baList.size(); ++item) {
							BankAccount ts = (BankAccount) baList.get(item);
							if (ts.getId() == baItems.getBankAccountId()) {
								i = ts.getBankName();
								if (ts.getAccountName() != null
										&& !ts.getAccountName().equals("")) {
									i = i + "(" + ts.getAccountName() + ")";
								}
								break;
							}
						}
					}

					tmpList.put("id", Long.valueOf(baItems.getId()));
					tmpList.put("receName",
							PageHelper.parseNull(baItems.getReceiverName()));
					tmpList.put("cost", baItems.getCost());
					tmpList.put("date", sf.format(baItems.getFeeDate()));
					tmpList.put("baName", i);
					tmpList.put("creaName", baItems.getCreaterName());
					tmpList.put("creaTime", tsItems);
					tmpList.put("mark", PageHelper.parseNull(baItems.getMark()));
					if (baItems.getExamined().equals("Y")) {
						tmpList.put("stat", "EXAM");
					} else {
						tmpList.put("stat", "UNEXAM");
					}

					items.add(tmpList);
				}

				map.put("items", items);
				if (initQuer != null && initQuer.equals("Y")) {
					EnterpriseInfo arg40 = EncCommonHelper
							.getEnterpriseInfo(request);
					List arg41 = PageHelper.parseBaList(baList, arg40, ub, 0L,
							0L);
					ArrayList arg42 = new ArrayList();

					for (int arg43 = 0; arg43 < arg41.size(); ++arg43) {
						HashMap arg45 = new HashMap();
						BankAccount arg47 = (BankAccount) arg41.get(arg43);
						String arg49 = arg47.getBankName();
						if (arg47.getAccountName() != null
								&& !arg47.getAccountName().equals("")) {
							arg49 = arg49 + "(" + arg47.getAccountName() + ")";
						}

						arg45.put("id", Long.valueOf(arg47.getId()));
						arg45.put("name", arg49);
						arg42.add(arg45);
					}

					arg41 = PageHelper.getTallySetList(this.tallySetDao, ub);
					ArrayList arg44 = new ArrayList();

					for (int arg46 = 0; arg46 < arg41.size(); ++arg46) {
						HashMap arg48 = new HashMap();
						TallySet arg50 = (TallySet) arg41.get(arg46);
						arg48.put("id", Long.valueOf(arg50.getId()));
						arg48.put("name", arg50.getTitle());
						arg44.add(arg48);
					}

					map.put("baItems", arg42);
					map.put("tsItems", arg44);
				}

				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg36) {
				map.put("status", "ERROR");
				map.put("errMsg", arg36.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg37 = new ObjectMapper();
		json = arg37.writeValueAsString(map);
		ServletOutputStream arg38 = response.getOutputStream();
		arg38.write(json.getBytes("utf-8"));
		arg38.flush();
		arg38.close();
		return null;
	}

	public ModelAndView handleAppInfo(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();

		try {
			long mapper = Long.parseLong(request.getParameter("id"));
			FeeBill out = (FeeBill) this.feeBillDao.get(FeeBill.class, mapper);
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
			SimpleDateFormat sfl = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			String bankName = "";
			String tsName = "";
			String creaTime = "";
			String depa = "";
			if (out.getBankAccountId() != 0L) {
				BankAccount ts = (BankAccount) this.feeBillDao.get(
						BankAccount.class, out.getBankAccountId());
				if (ts != null) {
					bankName = ts.getBankName();
					if (ts.getAccountName() != null
							&& !ts.getAccountName().equals("")) {
						bankName = bankName + "(" + ts.getAccountName() + ")";
					}
				}
			}

			if (out.getDepartmentId() != 0L) {
				Department arg24 = (Department) this.feeBillDao.get(
						Department.class, out.getDepartmentId());
				if (arg24 != null) {
					depa = arg24.getDepartmentName();
				}
			}

			TallySet arg25 = (TallySet) this.feeBillDao.get(TallySet.class,
					out.getTallySetId());
			if (arg25 != null) {
				tsName = arg25.getTitle();
			}

			if (out.getCreateTime() != null) {
				creaTime = sfl.format(out.getCreateTime());
			}

			map.put("id", Long.valueOf(out.getId()));
			map.put("receName", PageHelper.parseNull(out.getReceiverName()));
			map.put("code", out.getBillCode());
			map.put("date", sf.format(out.getFeeDate()));
			map.put("mark", PageHelper.parseNull(out.getMark()));
			map.put("cost", out.getCost());
			map.put("ba", bankName);
			map.put("depa", depa);
			map.put("mngName", out.getManagerName());
			map.put("creaName", out.getCreaterName());
			map.put("creaTime", creaTime);
			map.put("exam", out.getExamined());
			String examName = "";
			String examTime = "";
			if (out.getExamined().equals("Y")) {
				examName = out.getExaminerName();
				if (out.getExamineTime() != null) {
					examTime = sfl.format(out.getExamineTime());
				}
			}

			map.put("examName", examName);
			map.put("examTime", examTime);
			map.put("tsName", tsName);
			ArrayList items = new ArrayList();
			List typeList = this.feeTypeDao.getList(false);
			List itemList = this.feeBillItemDao.getList(out.getId());

			for (int i = 0; i < itemList.size(); ++i) {
				HashMap item = new HashMap();
				FeeBillItem bi = (FeeBillItem) itemList.get(i);
				item.put("cost", bi.getCost());
				item.put(
						"ftName",
						EncCommonHelper.getSimpleObjectName(typeList,
								bi.getFtId()));
				item.put("mark", bi.getMark());
				item.put("bbCode", bi.getBbCode());
				item.put("bbId", Long.valueOf(bi.getBbId()));
				items.add(item);
			}

			map.put("items", items);
			map.put("status", "OK");
			map.put("errMsg", "");
		} catch (Exception arg21) {
			map.put("status", "ERROR");
			map.put("errMsg", arg21.toString());
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg22 = new ObjectMapper();
		String json = arg22.writeValueAsString(map);
		ServletOutputStream arg23 = response.getOutputStream();
		arg23.write(json.getBytes("utf-8"));
		arg23.flush();
		arg23.close();
		return null;
	}

	public ModelAndView handleAppListForExam(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String json;
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else if (!EncCommonHelper.checkPrivilege(request, "FEE_EXAM")) {
			map.put("status", "ERROR");
			map.put("errMsg", "您还没有此功能的使用权限，请确认返回！");
		} else {
			try {
				String mapper = request.getParameter("sk");
				json = request.getParameter("ts_id");
				String out = request.getParameter("show_prev");
				String initQuer = request.getParameter("init_quer");
				long tsId = 0L;
				if (json != null && !json.equals("")) {
					tsId = Long.parseLong(json);
				}

				Date allowStart = null;
				if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
					allowStart = EncCommonHelper.getEarlDataDate(request);
				}

				int total = 0;
				BigDecimal cost = new BigDecimal(0);
				List list = this.feeBillDao.getAppListForExamCount(mapper,
						tsId, ub, allowStart);
				if (list.size() > 0 && list.get(0) != null) {
					Object[] perPageNum = (Object[]) list.get(0);
					if (perPageNum[1] != null) {
						total = Integer.parseInt(perPageNum[0].toString());
						cost = (BigDecimal) perPageNum[1];
					}
				}

				int arg30 = EncCommonHelper.getPageSize(request);
				int pageno = EncCommonHelper.getCurrentPageIndex(request,
						total, arg30);
				if (total > pageno * arg30) {
					map.put("more", "Y");
				} else {
					map.put("more", "N");
				}

				map.put("cost", cost);
				map.put("total", Integer.valueOf(total));
				if (out != null && out.equals("Y")) {
					list = this.feeBillDao.getAppListForExam(mapper, tsId, ub,
							allowStart, 0, pageno * arg30);
				} else {
					list = this.feeBillDao.getAppListForExam(mapper, tsId, ub,
							allowStart, (pageno - 1) * arg30, arg30);
				}

				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat sfl = new SimpleDateFormat("yyyy-MM-dd HH:mm");
				List baList = this.bankAccountDao.getList("", "");
				ArrayList items = new ArrayList();

				for (int tmpList = 0; tmpList < list.size(); ++tmpList) {
					FeeBill tsItems = (FeeBill) list.get(tmpList);
					String i = "";
					String item = "";
					if (tsItems.getCreateTime() != null) {
						i = sfl.format(tsItems.getCreateTime());
					}

					if (tsItems.getBankAccountId() != 0L) {
						for (int ts = 0; ts < baList.size(); ++ts) {
							BankAccount ba = (BankAccount) baList.get(ts);
							if (ba.getId() == tsItems.getBankAccountId()) {
								item = ba.getBankName();
								if (ba.getAccountName() != null
										&& !ba.getAccountName().equals("")) {
									item = item + "(" + ba.getAccountName()
											+ ")";
								}
								break;
							}
						}
					}

					HashMap arg35 = new HashMap();
					arg35.put("cost", tsItems.getCost());
					arg35.put("creaName", tsItems.getCreaterName());
					arg35.put("creaTime", i);
					arg35.put("receName",
							PageHelper.parseNull(tsItems.getReceiverName()));
					arg35.put("id", Long.valueOf(tsItems.getId()));
					arg35.put("date", sf.format(tsItems.getFeeDate()));
					arg35.put("baName", item);
					items.add(arg35);
				}

				map.put("items", items);
				if (initQuer != null && initQuer.equals("Y")) {
					List arg31 = PageHelper.getTallySetList(this.tallySetDao,
							ub);
					ArrayList arg32 = new ArrayList();

					for (int arg33 = 0; arg33 < arg31.size(); ++arg33) {
						HashMap arg34 = new HashMap();
						TallySet arg36 = (TallySet) arg31.get(arg33);
						arg34.put("id", Long.valueOf(arg36.getId()));
						arg34.put("name", arg36.getTitle());
						arg32.add(arg34);
					}

					map.put("tsItems", arg32);
				}

				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg27) {
				map.put("status", "ERROR");
				map.put("errMsg", arg27.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg28 = new ObjectMapper();
		json = arg28.writeValueAsString(map);
		ServletOutputStream arg29 = response.getOutputStream();
		arg29.write(json.getBytes("utf-8"));
		arg29.flush();
		arg29.close();
		return null;
	}

	public ModelAndView handleAppListForUnExam(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String json;
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else if (!EncCommonHelper.checkPrivilege(request, "FEE_UN_EXAM")) {
			map.put("status", "ERROR");
			map.put("errMsg", "您还没有此功能的使用权限，请确认返回！");
		} else {
			try {
				String mapper = request.getParameter("sk");
				json = request.getParameter("ts_id");
				String out = request.getParameter("show_prev");
				String initQuer = request.getParameter("init_quer");
				long tsId = 0L;
				if (json != null && !json.equals("")) {
					tsId = Long.parseLong(json);
				}

				Date allowStart = null;
				if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
					allowStart = EncCommonHelper.getEarlDataDate(request);
				}

				int total = this.feeBillDao.getAppListForUnExamCount(mapper,
						tsId, ub, allowStart);
				int perPageNum = EncCommonHelper.getPageSize(request);
				int pageno = EncCommonHelper.getCurrentPageIndex(request,
						total, perPageNum);
				if (total > pageno * perPageNum) {
					map.put("more", "Y");
				} else {
					map.put("more", "N");
				}

				List list;
				if (out != null && out.equals("Y")) {
					list = this.feeBillDao.getAppListForUnExam(mapper, tsId,
							ub, allowStart, 0, pageno * perPageNum);
				} else {
					list = this.feeBillDao.getAppListForUnExam(mapper, tsId,
							ub, allowStart, (pageno - 1) * perPageNum,
							perPageNum);
				}

				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat sfl = new SimpleDateFormat("yyyy-MM-dd HH:mm");
				List baList = this.bankAccountDao.getList("", "");
				ArrayList items = new ArrayList();

				for (int tmpList = 0; tmpList < list.size(); ++tmpList) {
					FeeBill tsItems = (FeeBill) list.get(tmpList);
					String i = "";
					String item = "";
					if (tsItems.getExamineTime() != null) {
						i = sfl.format(tsItems.getExamineTime());
					}

					if (tsItems.getBankAccountId() != 0L) {
						for (int ts = 0; ts < baList.size(); ++ts) {
							BankAccount ba = (BankAccount) baList.get(ts);
							if (ba.getId() == tsItems.getBankAccountId()) {
								item = ba.getBankName();
								if (ba.getAccountName() != null
										&& !ba.getAccountName().equals("")) {
									item = item + "(" + ba.getAccountName()
											+ ")";
								}
								break;
							}
						}
					}

					HashMap arg33 = new HashMap();
					arg33.put("cost", tsItems.getCost());
					arg33.put("examName", tsItems.getExaminerName());
					arg33.put("examTime", i);
					arg33.put("receName",
							PageHelper.parseNull(tsItems.getReceiverName()));
					arg33.put("id", Long.valueOf(tsItems.getId()));
					arg33.put("date", sf.format(tsItems.getFeeDate()));
					arg33.put("baName", item);
					items.add(arg33);
				}

				map.put("items", items);
				if (initQuer != null && initQuer.equals("Y")) {
					List arg29 = PageHelper.getTallySetList(this.tallySetDao,
							ub);
					ArrayList arg30 = new ArrayList();

					for (int arg31 = 0; arg31 < arg29.size(); ++arg31) {
						HashMap arg32 = new HashMap();
						TallySet arg34 = (TallySet) arg29.get(arg31);
						arg32.put("id", Long.valueOf(arg34.getId()));
						arg32.put("name", arg34.getTitle());
						arg30.add(arg32);
					}

					map.put("tsItems", arg30);
				}

				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg26) {
				map.put("status", "ERROR");
				map.put("errMsg", arg26.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg27 = new ObjectMapper();
		json = arg27.writeValueAsString(map);
		ServletOutputStream arg28 = response.getOutputStream();
		arg28.write(json.getBytes("utf-8"));
		arg28.flush();
		arg28.close();
		return null;
	}

	public ModelAndView handleAppExam(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String status = "";
		String errMsg = "";
		if (ub == null) {
			status = "NO_LOGIN";
		} else {
			String map = request.getParameter("type");
			String mapper = request.getParameter("id");
			if (map != null && map.equals("UNEXAM")) {
				if (!EncCommonHelper.checkPrivilege(request, "FEE_UN_EXAM")) {
					status = "ERROR";
					errMsg = "您还没有此功能的使用权限，请确认返回！";
				} else {
					try {
						this.feeBillService.txUnExamine(Long.parseLong(mapper),
								ub, this.feeBillDao, this.feeBillItemDao,
								this.bankAccountBalanceDao,
								this.bankAccountDetailDao,
								this.businessBillDao, this.idGenerator);
						status = "OK";
					} catch (CannotAcquireLockException arg12) {
						status = "ERROR";
						errMsg = "事务冲突故障，请重新操作！";
					} catch (NotAllowException arg13) {
						status = "ERROR";
						errMsg = arg13.getMessage();
					}
				}
			} else if (!EncCommonHelper.checkPrivilege(request, "FEE_EXAM")) {
				status = "ERROR";
				errMsg = "您还没有此功能的使用权限，请确认返回！";
			} else {
				try {
					this.feeBillService.txExamine(Long.parseLong(mapper), ub,
							this.feeBillDao, this.feeBillItemDao,
							this.bankAccountBalanceDao, this.businessBillDao,
							this.idGenerator);
					status = "OK";
				} catch (NotAllowException arg10) {
					status = "ERROR";
					errMsg = arg10.getMessage();
				} catch (CannotAcquireLockException arg11) {
					status = "ERROR";
					errMsg = "事务冲突故障，请重新操作！";
				}
			}
		}

		HashMap map1 = new HashMap();
		map1.put("status", status);
		map1.put("errMsg", errMsg);
		ObjectMapper mapper1 = new ObjectMapper();
		String json = mapper1.writeValueAsString(map1);
		ServletOutputStream out = response.getOutputStream();
		out.write(json.getBytes("utf-8"));
		out.flush();
		out.close();
		return null;
	}

	public String getDialogSuccessView() {
		return this.dialogSuccessView;
	}

	public void setDialogSuccessView(String dialogSuccessView) {
		this.dialogSuccessView = dialogSuccessView;
	}

	public FeeBillDao getFeeBillDao() {
		return this.feeBillDao;
	}

	public void setFeeBillDao(FeeBillDao feeBillDao) {
		this.feeBillDao = feeBillDao;
	}

	public String getInfoForExamineView() {
		return this.infoForExamineView;
	}

	public void setInfoForExamineView(String infoForExamineView) {
		this.infoForExamineView = infoForExamineView;
	}

	public String getInfoForUnExamineView() {
		return this.infoForUnExamineView;
	}

	public void setInfoForUnExamineView(String infoForUnExamineView) {
		this.infoForUnExamineView = infoForUnExamineView;
	}

	public String getListForExamineView() {
		return this.listForExamineView;
	}

	public void setListForExamineView(String listForExamineView) {
		this.listForExamineView = listForExamineView;
	}

	public String getListForUnExamineView() {
		return this.listForUnExamineView;
	}

	public void setListForUnExamineView(String listForUnExamineView) {
		this.listForUnExamineView = listForUnExamineView;
	}

	public String getSearchResultView() {
		return this.searchResultView;
	}

	public void setSearchResultView(String searchResultView) {
		this.searchResultView = searchResultView;
	}

	public DepartmentDao getDepartmentDao() {
		return this.departmentDao;
	}

	public void setDepartmentDao(DepartmentDao departmentDao) {
		this.departmentDao = departmentDao;
	}

	public QueryDao getQueryDao() {
		return this.queryDao;
	}

	public void setQueryDao(QueryDao queryDao) {
		this.queryDao = queryDao;
	}

	public String getDownloadView() {
		return this.downloadView;
	}

	public void setDownloadView(String downloadView) {
		this.downloadView = downloadView;
	}

	public String getInfoForCancelView() {
		return this.infoForCancelView;
	}

	public void setInfoForCancelView(String infoForCancelView) {
		this.infoForCancelView = infoForCancelView;
	}

	public String getListForCancelView() {
		return this.listForCancelView;
	}

	public void setListForCancelView(String listForCancelView) {
		this.listForCancelView = listForCancelView;
	}

	public FeeBillService getFeeBillService() {
		return this.feeBillService;
	}

	public void setFeeBillService(FeeBillService feeBillService) {
		this.feeBillService = feeBillService;
	}

	public DataSource getDataSource() {
		return this.dataSource;
	}

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}

	public BankAccountBalanceDao getBankAccountBalanceDao() {
		return this.bankAccountBalanceDao;
	}

	public void setBankAccountBalanceDao(
			BankAccountBalanceDao bankAccountBalanceDao) {
		this.bankAccountBalanceDao = bankAccountBalanceDao;
	}

	public BankAccountDetailDao getBankAccountDetailDao() {
		return this.bankAccountDetailDao;
	}

	public void setBankAccountDetailDao(
			BankAccountDetailDao bankAccountDetailDao) {
		this.bankAccountDetailDao = bankAccountDetailDao;
	}

	public IdGenerator getIdGenerator() {
		return this.idGenerator;
	}

	public void setIdGenerator(IdGenerator idGenerator) {
		this.idGenerator = idGenerator;
	}

	public BankAccountDao getBankAccountDao() {
		return this.bankAccountDao;
	}

	public void setBankAccountDao(BankAccountDao bankAccountDao) {
		this.bankAccountDao = bankAccountDao;
	}

	public FeeTypeDao getFeeTypeDao() {
		return this.feeTypeDao;
	}

	public void setFeeTypeDao(FeeTypeDao feeTypeDao) {
		this.feeTypeDao = feeTypeDao;
	}

	public PayModeDao getPayModeDao() {
		return this.payModeDao;
	}

	public void setPayModeDao(PayModeDao payModeDao) {
		this.payModeDao = payModeDao;
	}

	public TallySetDao getTallySetDao() {
		return this.tallySetDao;
	}

	public void setTallySetDao(TallySetDao tallySetDao) {
		this.tallySetDao = tallySetDao;
	}

	public BusinessBillDao getBusinessBillDao() {
		return this.businessBillDao;
	}

	public void setBusinessBillDao(BusinessBillDao businessBillDao) {
		this.businessBillDao = businessBillDao;
	}

	public String getListForBusinessBillView() {
		return this.listForBusinessBillView;
	}

	public void setListForBusinessBillView(String listForBusinessBillView) {
		this.listForBusinessBillView = listForBusinessBillView;
	}

	public String getPrintView() {
		return this.printView;
	}

	public void setPrintView(String printView) {
		this.printView = printView;
	}

	public CodeRuleDao getCodeRuleDao() {
		return this.codeRuleDao;
	}

	public void setCodeRuleDao(CodeRuleDao codeRuleDao) {
		this.codeRuleDao = codeRuleDao;
	}
}